package com.falm.picturebackend.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.falm.picturebackend.entity.DO.FilesDO;
import com.falm.picturebackend.mapper.FilesDOMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class FileDODao {

    @Resource
    private FilesDOMapper filesDOMapper;

    public FilesDO getFileByFullPath(String fullPath) {
        LambdaQueryWrapper<FilesDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FilesDO::getFullPath, fullPath);
        return filesDOMapper.selectOne(queryWrapper);
    }

    public void batchInsert(List<FilesDO> filesDOS) {
        filesDOMapper.insert(filesDOS);
    }

    public List<FilesDO> getAllFile() {
        return filesDOMapper.selectList(new QueryWrapper<>());
    }

    public void deleteFileByFullPath(String fullPath) {
        LambdaQueryWrapper<FilesDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FilesDO::getFullPath, fullPath);
        filesDOMapper.delete(queryWrapper);
    }
}
